Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto generate Event Ids in the logging source gen #87892

Merged
merged 4 commits into from
Jun 24, 2023

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Jun 21, 2023

No description provided.

@ghost
Copy link

ghost commented Jun 21, 2023

Tagging subscribers to this area: @dotnet/area-extensions-logging
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: tarekgh
Assignees: -
Labels:

area-Extensions-Logging

Milestone: -

@tarekgh tarekgh added this to the 8.0.0 milestone Jun 21, 2023
@tarekgh
Copy link
Member Author

tarekgh commented Jun 21, 2023

@geeknoid @stephentoub

@@ -298,8 +308,7 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
}

// ensure there are no duplicate event ids.
// LoggerMessageAttribute has constructors that don't take an EventId, we need to exclude the default Id -1 from duplication checks.
if (lm.EventId != -1 && !eventIds.Add(lm.EventId))
if (!eventIds.Add(lm.EventId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean someone could get a diagnostic because the generated ID happened to conflict?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch.

Copy link
Member Author

@tarekgh tarekgh Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean someone could get a diagnostic because the generated ID happened to conflict?

IMO this is reasonable to happen. At that time users can opt-in providing their own id. This will better than just allowing the same Id for multiple logging methods. In same time I want to avoid generating different id in case of collisions as I want to have the generated Id value is predictable and consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephentoub any more thoughts here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize the failure is very unlikely to occur, but if it does occur, it will be quite confusing for the customer. Imagine if the C# compiler sometimes just failed to compile a C# source file because it has a hash collision in the names of the symbols in the type.

What else can we do?

If there's a conflict, could we just increment the id value by 1 and try again until we find an unused id?

Copy link
Member Author

@tarekgh tarekgh Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a conflict, could we just increment the id value by 1 and try again until we find an unused id?

This is what I am trying to avoid. This means we can generate a different Id when other parts of the code change.

Imagine a scenario where we generate Id without any conflict and this code ships. Later in v2, more logger methods added cause a conflict which causes us to regenrate the Id for the methods which previously shipped. This kind of breaking changes if anyone dependent on the Id generated in v1.

I think getting diagnostics when Id collision occurs is not that bad especially it is unlikely to happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think such a diagnostic is problematic. We were willing to live with duplicate IDs when they defaulted to -1, I'm not sure why we're not willing to live with them when they default to something else.

I'd be fine with:

  1. Just not auto-generating IDs, and if you care about IDs, assign one.
  2. Auto-generating IDs but not warning when they conflict.

I don't think we should auto-generate IDs and warn when they conflict. Then harmless activities like tweaking a logging method name can start producing new seemingly unrelated and haphazard warnings.

Copy link
Member Author

@tarekgh tarekgh Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I applied no. 2 in the commit b1d5a89 (#87892)

@tarekgh tarekgh merged commit 3195fbb into dotnet:main Jun 24, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants